#pragma once

/////
////循环队列类型定义

template <typename E,int M>
struct SqQueue
{
    E elem[M];
    int front,rear;
};

///////////
///循环队列基本操作

///初始化循环队列为空 
template <typename E, int M>
void InitQueue(SqQueue<E,M> &Q)
{
    Q.front =Q.rear =0;
}

///判断队列是否为空
template <typename E, int M>
bool QueueEmpty(const SqQueue<E,M> &Q)
{
    return Q.front == Q.rear;
}

///入队列
template <typename E, int M>
void EnQueue(SqQueue<E,M> &Q, E e)
{
//若队列满，则抛出异常
if ((Q.rear+1)%M == Q.front) throw "Queue full";
//否则e入队列
Q.elem[Q.rear] = e;
Q.rear = (Q.rear + 1)%M;
}


template <typename E,int M>
void DeQueue(SqQueue<E,M> &Q,E &e)
{

    if (Q.front == Q.rear) throw "Queue empty";

    e=Q.elem[Q.front];
    Q.front = (Q.front +1)% M;
}


template <typename E, int M>
void DeQueue(SqQueue<E,M> &Q)
{

    if (Q.front == Q.rear) throw "Queue empty";

    Q.front = (Q.front +1)%M;
}


template <typename E,int M>
void GetHead(const SqQueue<E,M> &Q, E &e)
{

    if(Q.front == Q.rear) throw "Queue empty";

    e=Q.elem[Q.front];
}


template <typename E,int M>
E GetHead(const SqQueue<E,M> &Q)
{

    if (Q.front == Q.rear) throw "Queue empty";

    return Q.elem[Q.front];
}